package com.sylingd.blog.bean

import com.sylingd.blog.lib.Config
import java.text.SimpleDateFormat
import java.util.*


class Article(val id: Int,
		   val title: String,
		   val tags: String,
		   private val url: String?,
		   val body: String) {
	private var publish: Long = 0
		get() {
			return if (field.toString().length == 10) field * 1000 else field
		}

	val tagList: List<String> by lazy {
		tags.split(",")
	}

	fun formatDate(format: String): String {
		val formatter = SimpleDateFormat(format)
		formatter.timeZone = TimeZone.getDefault()
		return formatter.format(Date(publish))
	}

	fun getURL(): String {
		return if (url == null || url == "") Config.getArticleUrl(id) else url
	}

	override fun equals(other: Any?): Boolean {
		return other is Article && id == other.id
	}
}